package com.yksj.healthtalk.ui.buyandsell;

import java.util.List;

import org.handmark.pulltorefresh.library.PullToRefreshBase;
import org.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import org.handmark.pulltorefresh.library.PullToRefreshListView;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.yksj.healthtalk.adapter.FriendBaseAdapter;
import com.yksj.healthtalk.adapter.FriendBaseAdapter.onClickFriendAttentionListener;
import com.yksj.healthtalk.adapter.FriendBaseAdapter.onClickFriendHeadListener;
import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.comm.ZoomImgeDialogFragment;
import com.yksj.healthtalk.entity.ShopperEntity;
import com.yksj.healthtalk.net.http.HttpRestClient;
import com.yksj.healthtalk.net.http.ObjectHttpResponseHandler;
import com.yksj.healthtalk.ui.R;
/**
 * 购买者列表
 * @author Administrator
 *
 */
public class ShopperListActivity extends BaseFragmentActivity implements OnClickListener, OnRefreshListener<ListView>, OnItemClickListener,onClickFriendAttentionListener,onClickFriendHeadListener{

	private PullToRefreshListView refreshListView;
	private ListView mListView;
	private FriendBaseAdapter mAdapter;
	private int PAGENUM=1;
	private String MERCHANTID;
	private String GOODSID;
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.shopper_list_layout);
		initTitle();
		initView();
	}

	private void initView() {
		titleLeftBtn.setOnClickListener(this);
		titleTextV.setText("购买者");
		refreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_listview);
		mListView = refreshListView.getRefreshableView();
		refreshListView.setOnRefreshListener(this);
		mAdapter = new FriendBaseAdapter(this);
		mListView.setAdapter(mAdapter);
		mListView.setOnItemClickListener(this);
		MERCHANTID=getIntent().getStringExtra("MERCHANTID");
		GOODSID=getIntent().getStringExtra("GOODSID");
		initData();
	}

	/**
	 * OPTION=BUYINFO
	CUSTOMERID 客户ID
	MERCHANTID 商品商户ID
	GOODSID=7433 商品ID
	PAGENUM=1 页号
	PAGECOUNT=20 页面数量
	 */
	
	private void initData() {
		HttpRestClient.doHttpRecommentShopperList(MERCHANTID,GOODSID,PAGENUM+"",new ObjectHttpResponseHandler(this) {
			@Override
			public Object onParseResponse(String content) {
				return ShopperEntity.parseToList(content);
			}
			@Override
			public void onSuccess(int statusCode, Object response) {
				super.onSuccess(statusCode, response);
				if(response==null)return ;
				mAdapter.onBoundData((List<ShopperEntity>)response);
				PAGENUM++;
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_back:
			onBackPressed();
			break;
		}
	}

	@Override
	public void onRefresh(PullToRefreshBase<ListView> refreshView) {
		initData();
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		
	}

	@Override
	public void onClickFriendHead(ShopperEntity entity, int positon) {
		if (!TextUtils.isEmpty(entity.getBIG_ICON_BACKGROUND())) {
			ZoomImgeDialogFragment.show(entity.getBIG_ICON_BACKGROUND(),getSupportFragmentManager());
		}
	}

	@Override
	public void onClickFriendAttention(String attentioned,
			ShopperEntity entity, int positon) {
		
	}

}
